import Axios from "axios";
import {save_tips_list_data, save_type_tips_data} from "./constants";

export const requestTypeTipsData = () => {

    return (dispatch) => {
        Axios.get("/project/tree/json")
            .then((res) => {
                console.log(`请求分类数据 =-> `);
                console.log(res.data);

                const data = res.data.data;
                const action = saveTypeTipsData(data);
                dispatch(action);

                const id = data[0].id;
                const listDataAction = requestTipsListData(id,1);
                dispatch(listDataAction);
            })

    }
};

export const saveTypeTipsData = (data) => ({

    type: save_type_tips_data,
    data:data

});

//页码从 1 开始
export const requestTipsListData =(cid,page)=>{
    return (dispatch) =>{
        Axios.get(`/project/list/${page}/json?cid=${cid}`)
            .then((res) => {
                console.log("请求分类下面具体的数据");
                console.log(res.data);

                const datas = res.data.data.datas;
                const action = saveTipsListData(datas);
                dispatch(action);
            })
    }
};

export const saveTipsListData = (data) =>({
    type: save_tips_list_data,
    data:data
});


